package com.clx.risk.flink.demo.sinks;

import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.streaming.connectors.redis.common.mapper.RedisCommand;
import org.apache.flink.streaming.connectors.redis.common.mapper.RedisCommandDescription;
import org.apache.flink.streaming.connectors.redis.common.mapper.RedisMapper;

/**
 * 自定义redis数据类型的映射
 */
public class HashSetRedisMapper implements RedisMapper<Tuple2<Integer, Integer>> {
    /**
     * 设定数据结构
     *
     * @return
     */
    @Override
    public RedisCommandDescription getCommandDescription() {
        return new RedisCommandDescription(RedisCommand.HSET, "flinkset");
    }

    @Override
    public String getKeyFromData(Tuple2<Integer, Integer> data) {
        return String.valueOf(data.f0);
    }

    @Override
    public String getValueFromData(Tuple2<Integer, Integer> data) {
        return String.valueOf(data.f1);
    }
}